using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;


using PdfSharp.Drawing;

namespace DeltaFlex.Eines
{
    public class PDFBorder
    {
        #region [ Enums ]

        public enum LineStyle
        {
            None,
            Simple,
            Test,
            Double,
        };

        private const double COLUMN_WIDTH_REDUCTION = 20;

        #endregion
        
        #region [ Properties ]

        private LineStyle _up;
        private LineStyle _down;
        private LineStyle _left;
        private LineStyle _right;
        private Color _lineColor;
        private double _colWidthReduction = COLUMN_WIDTH_REDUCTION; //5 por defecto

        public LineStyle Up
        {
            get { return this._up; }
            set { this._up = value; }
        }

        public LineStyle Down
        {
            get { return this._down; }
            set { this._down = value; }
        }

        public LineStyle Left
        {
            get { return this._left; }
            set { this._left = value; }
        }

        public LineStyle Right
        {
            get { return this._right; }
            set { this._right = value; }
        }

        public Color LineColor
        {
            get { return this._lineColor; }
            set { this._lineColor = value; }
        }

        public double ColWidthReduction
        {
            get { return this._colWidthReduction; }
            set { this._colWidthReduction = value; }
        }

        #endregion

        #region [ Constructors ]

        public PDFBorder()
            : this(Color.Black, LineStyle.None, LineStyle.None, LineStyle.None, LineStyle.None, COLUMN_WIDTH_REDUCTION)
        { }

        public PDFBorder(LineStyle lineStyle)
            : this(lineStyle, COLUMN_WIDTH_REDUCTION)
        { }

        public PDFBorder(LineStyle lineStyle, double colReduction)
        {
            this._lineColor = Color.Black;

            this._down = lineStyle;
            this._up = lineStyle;
            this._right = lineStyle;
            this._left = lineStyle;

            this._colWidthReduction = colReduction;

        }

        public PDFBorder(LineStyle up, LineStyle down, LineStyle left, LineStyle right)
            : this(Color.Black, up, down, left, right, COLUMN_WIDTH_REDUCTION)
        { }

        public PDFBorder(Color lineColor, LineStyle up, LineStyle down, LineStyle left, LineStyle right)
            : this(lineColor, up, down, left, right, COLUMN_WIDTH_REDUCTION)
        { }

        public PDFBorder(Color lineColor, LineStyle up, LineStyle down, LineStyle left, LineStyle right, double colReduction)
        {
            this._down = down;
            this._up = up;
            this._left = left;
            this._right = right;
            this._lineColor = lineColor;
            this._colWidthReduction = colReduction;
        }

        #endregion

        #region [ Methods ]

        private double ConvertToLineWidth(LineStyle lineTipe)
        {
            switch (lineTipe)
            {
                case LineStyle.None:
                    return 0;
                case LineStyle.Simple:
                    return 0.5;
                case LineStyle.Double: 
                    return 2;
                case LineStyle.Test:
                    return 1;
                default:
                    return 0;
            }
        }

        public void DrawBorder(XGraphics gfx, double x, double y, double width, double height)
        {
            XPen pnU = new XPen(this._lineColor, this.ConvertToLineWidth(this._up));
            XPen pnD = new XPen(this._lineColor, this.ConvertToLineWidth(this._down));
            XPen pnL = new XPen(this._lineColor, this.ConvertToLineWidth(this._left));
            XPen pnR = new XPen(this._lineColor, this.ConvertToLineWidth(this._right));

            if (this._up != LineStyle.None)
            {
                // Pintamos la linia superior
                gfx.DrawLine(pnU, x - (pnL.Width / 2), y, x + width + (pnR.Width / 2), y);
            }
            if (this._down != LineStyle.None)
            {
                // Pintamos la linia inferior
                gfx.DrawLine(pnD, x - (pnL.Width / 2), y + height, x + width + (pnR.Width / 2), y + height);
            }
            if (this._left != LineStyle.None)
            {
                // Pintamos la linia izquierda
                gfx.DrawLine(pnL, x, y - (pnU.Width / 2), x, y + height + (pnD.Width / 2));
            }
            if (this._right != LineStyle.None)
            {
                // Pintamos la linia derecha
                gfx.DrawLine(pnR, x + width, y - (pnU.Width / 2), x + width, y + height + (pnD.Width / 2));
            }
        }

        #endregion
    }
}
